home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / c / bars.exe / BARS.C < prev   
C/C++ Source or Header  |  1992-02-29  |  11KB  |  448 lines

  1. /*
  2. **  BAR GRAPHS
  3. **
  4. **  was written in Turbo C++ in September, 1991.  This was
  5. **  my fourth program I had ever written, and was inspired
  6. **  by a couple of good books on GRAPHICS PROGRAMMING IN C++.
  7. **
  8. **  Leafing through the Library Reference to Turbo C++, I
  9. **  had frequently encountered graphic functions.  Not fully
  10. **  understanding what they did and how they interacted,
  11. **  I never used them.
  12. **
  13. **  Now that I am more than comfortable with Graphic programming,
  14. **  I am uploading this code to encourage more people to
  15. **  enthusiastically learn graphics.
  16. **
  17. **  Compile with:
  18. **
  19. **
  20. **     TCC -MS BAR.C EGAVGA.OBJ CGA.OBJ GRAPHICS.LIB
  21. **
  22. **  See your reference manual concerning how to transform
  23. **  CGA.LIB and EGAVGA.LIB into the objective files.
  24. **
  25. **  (or if you REALLY cannot figure it out, drop me a line ... )
  26. **
  27. **
  28. **
  29. **
  30. **                  Dave Smith
  31. **                CIS 71441,2723
  32. **
  33. */
  34.  
  35.  
  36. #include <graphics.h>
  37. #include <stdlib.h>
  38. #include <stdio.h>
  39. #include <conio.h>
  40. #include <dir.h>
  41. #include <dos.h>
  42.  
  43.  
  44.    /* THIS "DEFINE" SAVES MY LIFE LATER ...  YOU'LL SEE */
  45.  
  46. #define DUDE if(strstr(dta.ff_name,
  47.  
  48. void getfiles(void);
  49. void show(char *stuff, int w, int w2);
  50. void DRAWIT(int start, int minus);
  51.  
  52.   /* These should be re-done into a large integer array, but     */
  53.   /* for ease-of-reading purposes, I have left them as separate  */
  54.   /* entities.                             */
  55.  
  56. int zip,arj,arcs,zoo,pak,lzh,exe,bat,com,doc,txt,hlp,dat,tmp,log,eng,man;
  57. int bas,pas,a86,asms,obj,c,h,bak,tch,map,sys,dsk,set,cfg,prn,pcx,gif,tif;
  58. int mac,wpg,img,fra,cit,tga,bmp,ini,pif,grp,fon,dll,drv,mod, inf, bottom;
  59. int onlyhere=1;
  60. char origdir[30];
  61.  
  62. main(int argc, char *argv[])
  63. {
  64.  
  65. int gdriver = DETECT, gmode, errorcode;
  66. int farright, i, a, b, xmult, xdiv, ymult, ydiv;
  67.  
  68. getcwd(origdir, 30);
  69.  
  70.  
  71.  /*  Parse the command line and find out if we should change
  72.  **  directories or stay here, or leak into subdirectories also
  73.  */
  74.  
  75. if(argc==1) onlyhere=1;
  76. strupr(argv[1]);
  77. if(strstr(argv[1], "/S")){ onlyhere=0; chdir("\\"); }
  78. if(strstr(argv[1], "\\")) chdir(argv[1]);
  79.  
  80.  
  81.  /*  Set the integers to ZERO.    And for those who continue to tell
  82.  **  me that initializing an integer automatically sets it to ZERO,
  83.  **  YOU ARE WRONG !   I get stuck with -1 as a constant.
  84.  */
  85.  
  86. zip=arj=arcs=zoo=pak=lzh=exe=bat=com=doc=txt=hlp=dat=tmp=log=eng=man=0;
  87. bas=pas=a86=asms=obj=c=h=bak=tch=map=sys=dsk=set=cfg=prn=0;
  88. pcx=gif=tif=mac=wpg=img=fra=cit=tga=0;
  89. bmp=ini=pif=grp=fon=dll=drv=mod=inf=0;
  90.  
  91.  
  92.   /* INITIALIZE GRAPHICS, CALL VGA, EGA, & CGA DRIVERS    */
  93.  
  94.  
  95. if(registerbgidriver(EGAVGA_driver) < 0) exit(1);
  96. if(registerbgidriver(CGA_driver) < 0) exit(1);
  97.  
  98. initgraph(&gdriver, &gmode, "");
  99.  
  100. errorcode=graphresult();
  101. if(errorcode!=grOk)
  102.  {
  103.   printf("Graphics error: %s\n", grapherrormsg(errorcode));
  104.   printf("Press any key to halt:");
  105.   getch();
  106.   exit(1);
  107.  }
  108.  
  109.  farright=getmaxx();      /* OBTAIN MAXIMUM X AND Y COORDINATES */
  110.  bottom = getmaxy();
  111.  
  112.        setcolor(10);      /* Set the color to green ! */
  113.  
  114.  
  115.    /* DRAW MY LITTLE INTRODUCTION SCREEN */
  116.  
  117.  line(5, 5, 5, bottom-30);
  118.  line(5,bottom-30, farright-40,bottom-30);
  119.  line(farright-40, bottom-30, farright-40,5);
  120.  line(73, bottom-30, 73, 5);
  121.  line(5, 5, farright-40, 5);
  122.  line(113, bottom-30, 113, 5);
  123.  line(163, bottom-30, 163, 5);
  124.  line(193, bottom-30, 193, 5);
  125.  line(293, bottom-30, 293, 5);
  126.  line(343, bottom-30, 343, 5);
  127.  line(433, bottom-30, 433, 5);
  128.  
  129.    /* AND MY AXIS */
  130.  
  131.  b=0;
  132.  for(i=bottom-30; i>25; i-=50){
  133.        setcolor(10);
  134.      line(5, i, farright-40, i);
  135.      moveto(farright-26, i);
  136.        setcolor(14);
  137.      if(b==0) outtext ("0" );
  138.      if(b==1) outtext ("25");
  139.      if(b==2) outtext ("50");
  140.      if(b==3) outtext ("75");
  141.      if(b==4) outtext("100");
  142.      if(b==5) outtext("125");
  143.      if(b==6) outtext("150");
  144.      if(b==7) outtext("175");
  145.      if(b==8) outtext("200");
  146.      b++;
  147.      }
  148.  
  149.    /*  AND THE INTRODUCTION SCREEN */
  150.  
  151.    setcolor(9);
  152.    outtextxy(535,bottom-290,"Dave's");
  153.    outtextxy(535,bottom-270,"File");
  154.    setcolor(8);
  155.    outtextxy(535,bottom-250,"Usage");
  156.    setcolor(9);
  157.    outtextxy(535,bottom-230,"Graph");
  158.    setcolor(11);
  159.    outtextxy(530,bottom-210,"(c) 1992");
  160.  
  161.  getfiles();  /*  GETFILES() GRABS THE FILES AND COMPARES THEIR  */
  162.           /*         EXTENSIONS              */
  163.  
  164.  
  165.  
  166.  /*  DRAW DIFFERENT BAR GRAPHS DEPENDENT UPON WHICH FILES
  167.   *         WE FIND IN EACH CATEGORY
  168.   */
  169.  
  170. setcolor(3);
  171. setfillstyle(1, 1);
  172.  
  173.  DRAWIT(15, zip);
  174.  DRAWIT(25, arcs);
  175.  DRAWIT(35, zoo);
  176.  DRAWIT(45, pak);
  177.  DRAWIT(55, arj);
  178.  DRAWIT(65, lzh);
  179.  
  180. setcolor(11);
  181. setfillstyle(2, 2);
  182.  
  183.  DRAWIT(75, exe);
  184.  DRAWIT(85, bat);
  185.  DRAWIT(95, com);
  186.  DRAWIT(105, bat);
  187.  
  188. setcolor(15);
  189. setfillstyle(3, 3);
  190.  
  191.  DRAWIT(115, doc);
  192.  DRAWIT(125, txt);
  193.  DRAWIT(135, hlp);
  194.  DRAWIT(145, log);
  195.  DRAWIT(155, man);
  196.  
  197. setcolor(9);
  198. setfillstyle(4, 4);
  199.  
  200.  DRAWIT(165, eng);
  201.  DRAWIT(175, dat);
  202.  DRAWIT(185, tmp);
  203.  
  204. setcolor(13);
  205. setfillstyle(10, 5);
  206.  
  207.  DRAWIT(195, bas);
  208.  DRAWIT(205, pas);
  209.  DRAWIT(215, a86);
  210.  DRAWIT(225, asms);
  211.  DRAWIT(235, obj);
  212.  DRAWIT(245, c);
  213.  DRAWIT(255, h);
  214.  DRAWIT(265, bak);
  215.  DRAWIT(275, tch);
  216.  DRAWIT(285, map);
  217.  
  218. setcolor(7);
  219. setfillstyle(11, 6);
  220.  
  221.  DRAWIT(295, sys);
  222.  DRAWIT(305, dsk);
  223.  DRAWIT(315, set);
  224.  DRAWIT(325, cfg);
  225.  DRAWIT(335, prn);
  226.  
  227. setcolor(6);
  228. setfillstyle(7, 7);
  229.  
  230.  DRAWIT(345, pcx);
  231.  DRAWIT(355, gif);
  232.  DRAWIT(365, tif);
  233.  DRAWIT(375, mac);
  234.  DRAWIT(385, wpg);
  235.  DRAWIT(395, img);
  236.  DRAWIT(405, fra);
  237.  DRAWIT(415, cit);
  238.  DRAWIT(425, tga);
  239.  
  240. setcolor(11);
  241. setfillstyle(8, 8);
  242.  
  243.  DRAWIT(435, bmp);
  244.  DRAWIT(445, ini);
  245.  DRAWIT(455, pif);
  246.  DRAWIT(465, grp);
  247.  DRAWIT(475, fon);
  248.  DRAWIT(485, dll);
  249.  DRAWIT(495, drv);
  250.  DRAWIT(505, mod);
  251.  DRAWIT(515, inf);
  252.  
  253. settextstyle(2, 0, 1);
  254.  
  255.   /* NOW DRAW BOTTOM LABELS FOR FILES */
  256.  
  257. setcolor(3 );  outtextxy(15,  bottom-25, "COMPR");
  258. setcolor(11);  outtextxy(75,  bottom-25, "EXEC");
  259. setcolor(15);  outtextxy(115, bottom-25, "DOCS");
  260. setcolor(9 );  outtextxy(165, bottom-25, "DAT");
  261. setcolor(13);  outtextxy(195, bottom-25, "PROGRAMMING");
  262. setcolor(7 );  outtextxy(295, bottom-25, "SYSTEM");
  263. setcolor(6 );  outtextxy(352, bottom-25, "GRAPHICS");
  264. setcolor(11);  outtextxy(445, bottom-25, "WINDOWS");
  265.  
  266.  
  267.  
  268.   /**  NOW LABEL EACH BAR GRAPH, THEN PLACE THE NUMBER OF FILES THAT
  269.    **  ARE CONTAINED IN THE CATEGORIES ABOVE THE BAR.  THIS TECHNIQUE
  270.    **  IS RATHER TRICKY, SINCE WE MIGHT GO SO FAR UP THAT THE
  271.    **  BAR AND WORD ARE OFF THE SCREEN !
  272.    */
  273.  
  274.   if(zip>10) show("zip", zip, 15 );
  275.   if(arcs>10)show("arc", arcs,25 );
  276.   if(zoo>10) show("zoo", zoo, 35 );
  277.   if(pak>10) show("pak", pak, 45 );
  278.   if(arj>10) show("arj", arj, 55 );
  279.   if(lzh>10) show("lzh", lzh, 65 );
  280.   if(exe>10) show("exe", exe, 75 );
  281.   if(bat>10) show("bat", bat, 85 );
  282.   if(com>10) show("com", com, 95 );
  283.   if(doc>10) show("doc", doc, 115);
  284.   if(txt>10) show("txt", txt, 125);
  285.   if(hlp>10) show("hlp", hlp, 135);
  286.   if(log>10) show("log", log, 145);
  287.   if(man>10) show("man", man, 155);
  288.   if(eng>10) show("eng", eng, 165);
  289.   if(dat>10) show("dat", dat, 175);
  290.   if(tmp>10) show("tmp", tmp, 185);
  291.   if(bas>10) show("bas", bas, 195);
  292.   if(pas>10) show("pas", pas, 205);
  293.   if(a86>10) show("a86", a86, 215);
  294.   if(asms>10)show("asm", asms,225);
  295.   if(obj>10) show("obj", obj, 235);
  296.   if(c>  10) show("c"  , c  , 245);
  297.   if(h>  10) show("h"  , h  , 255);
  298.   if(bak>10) show("bak", bak, 265);
  299.   if(tch>10) show("tch", tch, 275);
  300.   if(map>10) show("map", map, 285);
  301.   if(sys>10) show("sys", sys, 295);
  302.   if(dsk>10) show("dsk", dsk, 305);
  303.   if(set>10) show("set", set, 315);
  304.   if(cfg>10) show("cfg", cfg, 325);
  305.   if(prn>10) show("prn", prn, 335);
  306.   if(pcx>10) show("pcx", pcx, 345);
  307.   if(gif>10) show("gif", gif, 355);
  308.   if(tif>10) show("tif", tif, 365);
  309.   if(img>10) show("img", img, 395);
  310.   if(fra>10) show("fra", fra, 405);
  311.   if(bmp>10) show("bmp", bmp, 435);
  312.   if(ini>10) show("ini", ini, 445);
  313.   if(pif>10) show("pif", pif, 455);
  314.   if(grp>10) show("grp", grp, 465);
  315.   if(fon>10) show("fon", fon, 475);
  316.  
  317.  getch();
  318.  
  319. closegraph();
  320. chdir(origdir);
  321. exit(0);
  322. }
  323.  
  324.  
  325.      /*  THIS FUNCTION FI